package com.itheima.home_work.bank_credit;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class CreditAssessmentSystem {
    private static final Logger logger = LoggerFactory.getLogger("CreditAssessmentSystem");

    // 列表保存所有客户信息
    List<Customer> customers = new ArrayList<>();

    // 得到信用模型
    private CreditScoringModel model = new CreditScoringModel();

    public CreditAssessmentSystem() {
        // 初始化一些客户信息
        //初始化用户
        Customer customer1 = new Customer("123456", "zhangsan", 23, "男", false, "本科", 100000, 0, LocalDateTime.of(2022, 8, 11, 13, 28, 30));
        Customer customer2 = new Customer("123123", "lisi", 45, "男", true, "研究生", 300000, 100000, LocalDateTime.of(2012, 8, 11, 13, 28, 30));
        Customer customer3 = new Customer("123798", "wangwu", 65, "男", true, "本科", 5000, 0, LocalDateTime.of(2000, 8, 11, 13, 28, 30));
        customers.add(customer1);
        customers.add(customer2);
        customers.add(customer3);
    }

    //某个客户信用评估
    public void findAssessCreditById(String id) {

        final Customer customerNow = this.customers.stream()
                .filter(customer -> customer.getId().equals(id))
                .findFirst().orElse(null);

        if (customerNow != null) {
            this.printCustomCredit(customerNow);
            final DecisionSupportSystem decisionSupportSystem = new DecisionSupportSystem();
            decisionSupportSystem.makeLoanApprovalDecision(customerNow);
        } else {
            System.out.printf("未查询到卡号为 %s 的客户信息. ", id);
            System.out.println();
        }
    }

    //所有客户信用评估
    public void findAssessCredit() {
        this.customers.forEach(this::printCustomCredit);
    }

    // 查询客户的信用评估
    public void printCustomCredit(Customer customer) {
        final int score = model.calculateCreditScore(customer);
        final String info = String.format("客户 %s, 卡号 %s 信用评分为：%d", customer.getName(), customer.getId(), score);
//        System.out.println(info);
        logger.info(info);
    }
}
